﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls">


    <DataTemplate x:Key="PivotHeaderTemplate">
        <TextBlock Text="{Binding}" FontSize="{DynamicResource HeaderFontSize}" FontFamily="{DynamicResource HeaderFontFamily}"  />
    </DataTemplate>

    <Style x:Key="PivotListViewItem" TargetType="{x:Type ListViewItem}">
        <Setter Property="Foreground" Value="{DynamicResource BlackBrush}" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="MinHeight" Value="25" />
        <Setter Property="Margin" Value="0,0,0,0" />
        <Setter Property="Border.BorderBrush" Value="{DynamicResource Gray3}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListViewItem}">
                    <Border x:Name="Bd" SnapsToDevicePixels="true">
                        <Grid>
                            <GridViewRowPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                            <ContentPresenter x:Name="contentPresenter" Visibility="Collapsed" Opacity="0.35" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="GridView.ColumnCollection" Value="{x:Null}">
                            <Setter TargetName="contentPresenter" Property="Visibility" Value="Visible"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter TargetName="contentPresenter" Property="Opacity" Value="1" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="contentPresenter" Property="Opacity" Value="1" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    
    <Style TargetType="{x:Type Controls:Pivot}">
        <Setter Property="HeaderTemplate" Value="{StaticResource PivotHeaderTemplate}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:Pivot}">
                    <Grid x:Name="root">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <ContentPresenter Grid.Row="0" Content="{Binding Header, RelativeSource={RelativeSource AncestorType={x:Type Controls:Pivot}}}"  ContentTemplate="{TemplateBinding HeaderTemplate}" />
                        <ListView 
                            x:Name="PART_Headers"
                            Grid.Row="1"
                            BorderBrush="{x:Null}"
                            Style="{x:Null}"
                            ItemContainerStyle="{StaticResource PivotListViewItem}"
                            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                            ScrollViewer.VerticalScrollBarVisibility="Disabled"
                            ItemsSource="{Binding Items, RelativeSource={RelativeSource AncestorType={x:Type Controls:Pivot}}}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal" />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Header}" FontSize="{DynamicResource SubHeaderFontSize}" FontFamily="{DynamicResource HeaderFontFamily}" Margin="0,0,25,0"/>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ListView>

                        <ScrollViewer Grid.Row="2" x:Name="PART_Scroll" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto" VerticalAlignment="Stretch">
                            <ItemsControl x:Name="itemscontrol" Margin="0,0,250,0" ItemsSource="{Binding Items, RelativeSource={RelativeSource AncestorType={x:Type Controls:Pivot}}}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Horizontal" />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                            </ItemsControl>
                        </ScrollViewer>

                        <Controls:ScrollViewerOffsetMediator x:Name="PART_Mediator" ScrollViewer="{Binding ElementName=PART_Scroll}">
                            <Controls:ScrollViewerOffsetMediator.Resources>
                                <Storyboard x:Key="Storyboard1">
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="HorizontalOffset" Storyboard.TargetName="PART_Mediator">
                                        <EasingDoubleKeyFrame x:Name="edkf" KeyTime="0:0:0.6" Value="0">
                                            <EasingDoubleKeyFrame.EasingFunction>
                                                <CircleEase/>
                                            </EasingDoubleKeyFrame.EasingFunction>
                                        </EasingDoubleKeyFrame>
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>

                            </Controls:ScrollViewerOffsetMediator.Resources>
                        </Controls:ScrollViewerOffsetMediator>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Controls:PivotItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:PivotItem}">
                    <ContentPresenter />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>